package com.blockmeta.bbs.baselibrary.base.app;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import androidx.multidex.MultiDex;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blockmeta.bbs.baselibrary.BuildConfig;
import com.blockmeta.bbs.baselibrary.provider.ProjectBuildInfo;

import java.util.Map;

/**
 * @author AirThor
 * @date 2019/6/19.
 */
public class BaseApp extends Application {
    private static BaseApp mContext;
    protected ProjectBuildInfo projectBuildInfo;

    public static BaseApp getApp() {
        return mContext;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initARouter();


    }

    private void initARouter() {
        if (BuildConfig.DEBUG) {
            // 这两行必须写在init之前，否则这些配置在init过程中将无效
            // 打印日志
            ARouter.openLog();
            // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
            ARouter.openDebug();
        }
        ARouter.init((Application) mContext);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        mContext = this;
        MultiDex.install(base);
    }

    public static boolean isUseDefualtFont() {
        return true;
    }

    private static final Handler mHandler = new Handler();
    public static final void runOnUiThread(Runnable runnable) {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            runnable.run();
        } else {
            mHandler.post(runnable);
        }
    }

    public static String getApplicationId(){
        return mContext.getApplicationInfo().packageName;
    }

    public float getScreenWidhPixel() {
        return getResources().getDisplayMetrics().widthPixels;
    }


}
